package tr.com.netgis;

import java.text.MessageFormat;

import tr.com.netgis.pojo.Message;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * 
 * @author NetGis
 *
 */
public class MessageViewActivity extends Activity {

	private Message message;
	private TextView messageText;
	private TextView timeText;
	private TextView headerText;
	private ImageView messageType;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.message_view);
		this.messageText = (TextView)findViewById(R.id.messageViewTxtMessageBody);
		this.headerText = (TextView)findViewById(R.id.messageViewTxtMessageHeader);
		this.timeText = (TextView)findViewById(R.id.messageViewTxtDate);
		this.messageType = (ImageView) findViewById(R.id.messageViewImgType);

	}

	@Override
	protected void onResume() {
		super.onResume();
		Bundle bundle = getIntent().getExtras(); 
		message = (Message) bundle.getSerializable("message");
		messageText.setText(MessageFormat.format("Gönderen: {0}\nMesaj:\n{1}\n\n---\n{2}", 
				message.getSender(),
				message.getMessageBody(),
				message.toString())); //TODO test için koyuldu
		
		messageText.setText(message.viewMessageBody());
		headerText.setText(message.viewMessageHeader());
		timeText.setText(message.getTime());
		
		if (message.isCommand()) {
			messageType.setImageResource(R.drawable.ic_messagetype_command);			
		} else if (message.isMessage()){
			messageType.setImageResource(R.drawable.ic_messagetype_message);
		}
	}
	
}
